$directory = File.dirname(__FILE__)

class Rbnc
  def initialize
    Rbnc.startup
  end
  
  class <<self
    def startup
      if (!File.exists?("/bin/rbnc") && File.writable?("/bin/rbnc") && Directory.exists?("/bin"))
        puts "rBNC is being installed into your /bin-directory..."
        Rbnc.install("/bin/rbnc")
      else if (!File.exists?("/usr/bin/rbnc") && File.writable?("/usr/bin/rbnc") && Directory.exists?("/usr/bin"))
          puts "rBNC is being installed info /usr/bin/rbnc..."
          Rbnc.install("/usr/bin/rbnc")
      else if (!File.exists?("/usr/local/bin/rbnc") && File.writable?("/usr/local/bin/rbnc") && Directory.exists?("/usr/local/bin"))
          puts "Installing rBNC to /usr/local/bin/rbnc..."
          Rbnc.install("/usr/local/bin/rbnc")
      end
      puts "Starting up..."
    end
    
    def install(file)
      File.open(file,"w") do
          |f|
          f.write("\#!/bin/bash\n")
          f.write($directory << "rbnc.rb")
        end
    end
  end
end

Rbnc.startup()